// 小程序开发api接口统一配置
// const API_BASE_URL = 'http://127.0.0.1:10032';  // 主域名
const API_BASE_URL = 'https://douyin.juhang.co/prod-api';  // 主域名
const subdomain = "/app";

// const API_QINIU_URL = 'http://127.0.0.1:10032'; 
const API_QINIU_URL = 'https://douyin.juhang.co/prod-api'; 

const request = (url, method, data) => {
    let _url = API_BASE_URL + subdomain + url;
	// uni.showLoading({
	// 	title: '请求中...'
	// })
    return new Promise((resolve, reject) => {
        uni.request({
           url: _url,
           method: method,
           data: data,
           header: {
             'content-type': 'application/json'
           },
           success(request) {
			   resolve(request.data)
           },
           fail(error) {
             reject(error)
           },
           complete(aaa) {
             
           }
       })
    })
}
/**
 * 小程序的promise没有finally方法，自己扩展下
 */
Promise.prototype.finally = function (callback) {
  var Promise = this.constructor;
  return this.then(
    function (value) {
      Promise.resolve(callback()).then(
        function () {
          return value;
        }
      );
    },
    function (reason) {
      Promise.resolve(callback()).then(
        function () {
          throw reason;
        }
      );
    }
  );
}

export default{
	request,
	//获取图片地址
	getPath(){return API_QINIU_URL;},
	//获取请求地址
	getPathApi(){return API_BASE_URL;},
	
	//登录
	login: data => request('/login/login','post',data),
	//手机好快捷登录
	getPhone: data => request('/login/getPhone','post',data),
	
	//获取字典列表
	getPostList: data => request('/index/getPostList','get',data),
	//获取城市职位数据
	getPostGroupCity: data => request('/index/getPostGroupCity','get',data),
	//获取职位详情
	getPostById: data => request('/index/getPostById','get',data),
	//职位报名
	applyPost: data => request('/user/applyPost','post',data),
	//获取我报名的职位
	getApplyPostList: data => request('/user/getApplyPostList','get',data),

}